<?php


namespace app\sms\controller;


use think\Controller;
use think\Log;

class Notify extends Controller
{
    /**
     * 助通发送短信回执
     */
    public function zthysms()
    {
        // $headers = json_decode('{"pragma":"no-cache","cache-control":"no-cache","content-type":"application\/json","accept-language":"zh-CN,zh;q=0.8","accept-encoding":"gzip, deflate","zt-password":"6fba303edbf679b8912368e13eed5821","user-agent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/75.0.3770.142 Safari\/537.36 Hutool","zt-tkey":"1593497321","accept":"text\/html,application\/json,application\/xhtml+xml,application\/xml;q=0.9,*\/*;q=0.8","content-length":"179","x-scheme":"https","x-original-uri":"\/sms\/notify\/zthysms","x-forwarded-proto":"https","x-forwarded-port":"443","x-forwarded-host":"beta-wechat.goddessxzns.com","x-forwarded-for":"47.100.207.118","x-real-ip":"47.100.207.118","x-request-id":"fde518a7a60e6075276b461e51958316","host":"beta-wechat.goddessxzns.com"}', true);
        // $data = json_decode('[{"msgId":"159349047668812895744","mobile":"17333657763","reportTime":"2020-06-30 12:14:41","code":"DELIVRD","msg":"\u53d1\u9001\u6210\u529f","pkTotal":1,"pkNumber":1,"username":"xzns666yx"}]', true);
        //
        // $password = 'qh3QMByHU1mznTXv';
        // $b = md5($password);
        // $w = md5(md5($password) . $headers['zt-tkey']);
        // $b1 = md5('V337qi43');
        // $w2 = md5(md5('V337qi43') . $headers['zt-tkey']);
        // if($headers['zt-password'] === md5(md5($password) . $headers['zt-tkey'])){
        //     $a = 1;
        // }else{
        //     $a = 0;
        // }

        if ($this->request->isPost())
        {
            $data = $this->request->param();
            // 暂时取消进行鉴权动作 因为鉴权时用的password不是最新的密码 ；而且初始密码  以防有问题 所以取消鉴权
            // $headers = $this->request->header(['zt-tkey', 'zt-password']);
            // $password = 'qh3QMByHU1mznTXv';
            // if ($headers['zt-password'] === md5(md5($password) . $headers['zt-tkey']))
            // {   // 鉴权 成功
                foreach ($data as $item)
                {
                    $smsLog = [
                        'msg_id' => $item['msgId'],
                        'mobile' => $item['mobile'],
                        'report_time' => $item['reportTime'],
                        'code' => $item['code'],
                        'msg' => $item['msg'],
                        'pk_total' => $item['pkTotal'],
                        'pk_number' => $item['pkNumber'],
                        'username' => $item['username'],
                    ];

                    Log::write($smsLog, 'flog_birthday_sms_notify');
                }
            // }
        }
    }
}
